from zope.interface import implements, Interface

from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName

from my315ok.products import productsMessageFactory as _


class IproductView(Interface):
    """
    product view interface
    """
    def img_tag():
        """return image field tag"""
        
    def img_url():
        """return image absolute url"""    



class productView(BrowserView):
    """
    product browser view
    """
    implements(IproductView)

    def __init__(self, context, request):
        self.context = context
        self.request = request

    @property
    def portal_catalog(self):
        return getToolByName(self.context, 'portal_catalog')

    @property
    def portal(self):
        return getToolByName(self.context, 'portal_url').getPortalObject()

    def img_tag(self,scale,fieldname="image"):
        tag = self.contex.getField(fieldname).tag(self.context,scale)
        return tag
    def img_large_link(self,fieldname="image",large="large"):
        link = self.img_url() + "/" + fieldname + "_" + large
        return link
    def img_url(self):
        return self.context.absolute_url()
        
        
